package ua.org.nuos.sdms.clientgui.client.handlers;

import ua.org.nuos.sdms.clientgui.client.context.Messages;
import ua.org.nuos.sdms.clientgui.client.controller.GlobalBoard;
import ua.org.nuos.sdms.clientgui.client.events.ErrorMessageEvent;
import ua.org.nuos.sdms.clientgui.client.events.InfoMessageEvent;
import ua.org.nuos.sdms.clientgui.client.events.UpdateUserPasswordEvent;
import ua.org.nuos.sdms.clientgui.client.listeners.UpdateUserPasswordListener;
import ua.org.nuos.sdms.clientgui.server.AppProxy;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 25.03.12
 * Time: 16:15
 * To change this template use File | Settings | File Templates.
 */
public class UpdateUserPasswordHandler implements UpdateUserPasswordListener {
    @Override
    public void update(UpdateUserPasswordEvent event) {
        try {
            String password = event.getPassword();
            AppProxy.getInstance().getServiceLocator().getClientBean().changeCurrentUserPassword(password);
            AppProxy.getInstance().getControllerLocator().getController(GlobalBoard.ID).fire(new InfoMessageEvent(Messages.UPDATE_SUCCESSFULLY));
        } catch (Exception ex) {
            Logger.getAnonymousLogger().log(Level.WARNING, "Update user error", ex);
            AppProxy.getInstance().getControllerLocator().getController(GlobalBoard.ID).fire(new ErrorMessageEvent(Messages.ACTION_ERROR));
        }
    }
}
